// greedy algrithm
// 双指针法：每次移动较短边界
func maxArea(height []int) int {
	n := len(height)
	res := 0
	for i, j := 0, n-1; i < j; {
		res = max(res, (j-i)*min(height[j], height[i]))
		if height[i] < height[j] {
			// move to right
			i++
		} else {
			j--
		}
	}

	return res
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}